/**
 * COPYRIGHT HangZhou Trustway Technology Company Limited
 * All right reserved.
 */
package com.robam.cloud.authcenter.provider;

import com.robam.cloud.authcenter.helper.WechatHelper;
import com.robam.cloud.common.bean.restful.entity.RespMsg;
import com.robam.cloud.log.annotation.OperationLogRecord;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @Description
 * @Author 薛铁琪
 * @CreateTime 2020-08-11 10:20
 * @Version 1.0
 */
@Api("提供微信服务调用的控制类")
@RestController
@RequestMapping("/provider/wechat")
@Slf4j
public class WechatProvider {
    @Autowired
    HttpServletRequest request;
    @Autowired
    WechatHelper wechatHelper;

    @ApiOperation(
            value = "微信消息通知校验",
            notes = "微信消息通知校验")
    @RequestMapping(
            value = "/message",
            method = RequestMethod.GET)
    @OperationLogRecord(
            describe = "微信消息通知校验",
            modularCode = "provider-wechat-message",
            operationLevel = OperationLogRecord.OperationLevel.OTHER)
    public void notifyCheck(@RequestParam String signature, @RequestParam String timestamp, @RequestParam String nonce, @RequestParam String echostr, HttpServletResponse response) {
        wechatHelper.notifyCheck(signature, timestamp, nonce, echostr, response);
    }

    @ApiOperation(
            value = "微信消息通知",
            notes = "微信消息通知")
    @RequestMapping(
            value = "/message",
            method = RequestMethod.POST)
    @OperationLogRecord(
            describe = "微信消息通知",
            modularCode = "provider-wechat-message",
            operationLevel = OperationLogRecord.OperationLevel.OTHER)
    public RespMsg notify(@RequestBody byte[] data) {
        wechatHelper.provider(data, request);
        return RespMsg.success();
    }
}
